import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {FormBuilder, FormControl, FormGroup} from '@angular/forms';
import {TurbStatusService} from '../../service/turbstatus.service';

@Component({
  selector: 'app-color-choices',
  templateUrl: './color-choices.component.html',
  styleUrls: ['./color-choices.component.css']
})
export class ColorChoicesComponent implements OnInit {
  validationMessages: {};
  formErrors: {};
  fromBuider: FormBuilder;
  @Input() currentEntity: any;
  @Output() colorOut = new EventEmitter();
  myGroup: FormGroup;

  constructor(private fb: FormBuilder, private turbastatusService: TurbStatusService) {
    this.myGroup = fb.group({
      statusColor: new FormControl(''),
    });
  }

  ngOnInit() {
    this.myGroup.controls['statusColor'].setValue(this.currentEntity.statusColor)
    this.myGroup.controls['statusColor'].valueChanges
      .distinctUntilChanged()
      .subscribe((form: any) => {
        console.log(this.myGroup.valid)
        this.colorOut.emit({
          value: form,
          err: this.myGroup.valid
        });

      });


  }


}
